from django import template
#from django.utils.safestring import mark_safe, SafeData
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter
@stringfilter
def split_as_link(value, splitter=' ', autoescape=None):
    #if not isinstance(value, SafeData):
    #    value = mark_safe(value)
    value = value.split(splitter)
    result = ""
    for v in value:
        if v.startswith('http://'):
            result += '<a href="%s" target="_blank">%s</a> ' % (v, v)
        else:
            result += '%s ' % (v)
    #return mark_safe(result)
    return result
#split_as_link.is_safe = True
#split_as_link.needs_autoescape = True